package cn.ibizlab.odoo.core.odoo_board.service.impl;

import java.io.Serializable;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.HashMap;
import java.math.BigInteger;
import java.util.Collection;

import lombok.extern.slf4j.Slf4j;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cglib.beans.BeanCopier;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import cn.ibizlab.odoo.core.client.model.Iboard_board;
import cn.ibizlab.odoo.core.odoo_board.domain.Board_board;
import cn.ibizlab.odoo.core.odoo_board.filter.Board_boardSearchContext;
import cn.ibizlab.odoo.core.odoo_board.service.IBoard_boardService;
import cn.ibizlab.odoo.util.SearchResult;
import cn.ibizlab.odoo.util.log.IBIZLog;

/**
 * 实体[仪表板] 服务对象接口实现
 */
@Slf4j
@IBIZLog
@Service
public class Board_boardServiceImpl implements IBoard_boardService {

    @Autowired
    private cn.ibizlab.odoo.core.client.service.Iboard_boardClientService board_boardClientService;

    @Override
    public boolean update(Board_board board_board) {
        boolean bOk = false ;
        Iboard_board clientModel = this.convert2Model(board_board,null);
        board_boardClientService.update(clientModel) ;
        this.convert2Domain(clientModel,board_board) ;
        bOk = true;
        return bOk ;
    }

    @Override
    public void removeBatch(Collection<? extends Serializable> idList, int batchSize) {

        //board_boardClientService.removeBatch(board_boards) ;

    }

    @Override
    public void updateBatch(List<Board_board> board_boards, int batchSize) {

        //board_boardClientService.updateBatch(board_boards,batchSize) ;

    }

    @Override
    public boolean remove(Integer id) {
        boolean bOk = false ;
        Iboard_board clientModel = board_boardClientService.createModel();
        clientModel.setId(id);
        board_boardClientService.remove(clientModel) ;
        bOk = true ;
        return bOk ;
    }

    @Override
    public boolean create(Board_board board_board) {
        boolean bOk = false ;
        Iboard_board clientModel = this.convert2Model(board_board,null);
        board_boardClientService.create(clientModel) ;
        this.convert2Domain(clientModel,board_board);
        bOk = true ;

        return bOk ;
    }

    @Override
    public Board_board get(Integer id) {
        Iboard_board clientModel = board_boardClientService.createModel();
        clientModel.setId(id);
        board_boardClientService.get(clientModel) ;
        return this.convert2Domain(clientModel,null);
    }

    @Override
    public Board_board get(Board_board board_board) {
        Board_board retboard_board = this.get(board_board.getId()) ;
    	BeanCopier copier=BeanCopier.create(retboard_board.getClass(), board_board.getClass(), false);
        copier.copy(retboard_board, board_board, null);
        return board_board ;
    }

    @Override
    public void createBatch(List<Board_board> board_boards, int batchSize) {

                        //board_boardClientService.createBatch(board_boards,batchSize) ;

    }

    /**
     * 查询集合 默认查询
     */
    @Override
    public Page<Board_board> searchDefault(Board_boardSearchContext context) {
        List<Board_board> list = new ArrayList<Board_board>();
        Page<cn.ibizlab.odoo.core.client.model.Iboard_board> clientModelList = board_boardClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Iboard_board clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Board_board>(list, context.getPageable(), clientModelList.getTotalElements());
    }




    public Iboard_board convert2Model(Board_board domain , Iboard_board model) {
        if(domain == null)
            return model ;
        if(model==null){
            model = board_boardClientService.createModel() ;
        }

         if(domain.getDisplay_nameDirtyFlag())
            model.setDisplay_name(domain.getDisplay_name());
         if(domain.get__last_updateDirtyFlag())
            model.set__last_update(domain.get__last_update());
         if(domain.getIdDirtyFlag())
            model.setId(domain.getId());
        return model ;
    }

    public Board_board convert2Domain( Iboard_board model ,Board_board domain) {
        if(model == null)
            return domain ;
        if(domain == null){
            domain = new Board_board();
        }

        if(model.getDisplay_nameDirtyFlag())
            domain.setDisplay_name(model.getDisplay_name());
        if(model.get__last_updateDirtyFlag())
            domain.set__last_update(model.get__last_update());
        if(model.getIdDirtyFlag())
            domain.setId(model.getId());
        return domain ;
    }


}
